/*
  学习目标：购物车加减练习
*/

import React from 'react';
export default class App extends React.Component {
  state = {
    count: 0,
  };

  render() {
    return (
      <div>
        <p>当前数值为：{this.state.count}</p>
        <hr />
        <button onClick={() => this.handleClick(1)}>+1</button>
        <span>{this.state.count}</span>
        <button onClick={() => this.handleClick(-1)}>-1</button>
      </div>
    );
  }

  // 复用click函数
  handleClick(num) {
    // 🔔 setState修改时数据
    this.setState({
      count: this.state.count + num,
    });
  }
}
